package com.xiaoxin.experience.service.ssh.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.xiaoxin.experience.service.ssh.model.SSHSessionInfo;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;

/**
 * @author xiaoxin
 */
@Setter
@Getter
@TableName("tbl_ssh_info")
public class SSHEntity implements Serializable
{
    private static final long serialVersionUID = 6077618367254532436L;

    @TableId("ip")
    private String ip;

    @TableField("ssh_name")
    private String sshName;

    @TableField("port")
    private int port;

    @TableField("username")
    private String username;

    @TableField("password")
    private String password;

    @TableField("restart_server_command")
    private String restartServerCommand;

    public SSHEntity()
    {
    }

    public SSHEntity(SSHSessionInfo sshSessionInfo)
    {
        this.ip = sshSessionInfo.getIp();
        this.sshName = sshSessionInfo.getName();
        this.port = sshSessionInfo.getPort();
        this.username = sshSessionInfo.getUsername();
        this.password = sshSessionInfo.getPassword();
        this.restartServerCommand = sshSessionInfo.getRestartServerCommand();
    }

    public SSHSessionInfo toInfo()
    {
        SSHSessionInfo sshSessionInfo = new SSHSessionInfo();
        sshSessionInfo.setName(sshName);
        sshSessionInfo.setIp(ip);
        sshSessionInfo.setPort(port);
        sshSessionInfo.setUsername(username);
        sshSessionInfo.setPassword(password);
        sshSessionInfo.setRestartServerCommand(restartServerCommand);
        return sshSessionInfo;
    }
}
